def stall_here():
    """Stall because a resource is in use."""
    return False


def delay_here():
    """Stall because a branch might happen."""
    return False


def branch_here():
    """Here we branched."""
    return False


def get_pipeline_state(cycles, instructions):
    """WIP"""
    slug = -1
    start = 0
    pipeline_state = {
        "IF": slug,
        "ID": slug,
        "EX": slug,
        "MEM": slug,
        "WB": slug,
    }

    cycle_state = []

    for cycle in range(1, cycles + 1):
        # exit the pipeline
        if pipeline_state["WB"] != slug:
            pipeline_state["WB"] = slug

        # move to WB
        if pipeline_state["MEM"] != slug and not pipeline_state["WB"] != slug:
            if stall_here():
                continue
            pipeline_state["WB"] = pipeline_state["MEM"]
            pipeline_state["MEM"] = slug

        # move to MEM
        if pipeline_state["EX"] != slug and not pipeline_state["MEM"] != slug:
            if stall_here():
                continue
            if branch_here():
                # TODO: Get the actual instruction number for the branch.
                start = 0
                continue
            pipeline_state["MEM"] = pipeline_state["EX"]
            pipeline_state["EX"] = slug

        # move to EX
        if pipeline_state["ID"] != slug and not pipeline_state["EX"] != slug:
            if stall_here():
                continue
            pipeline_state["EX"] = pipeline_state["ID"]
            pipeline_state["ID"] = slug

        # move to ID
        if pipeline_state["IF"] != slug and not pipeline_state["ID"] != slug:
            if stall_here():
                continue
            pipeline_state["ID"] = pipeline_state["IF"]
            pipeline_state["IF"] = slug

        # move to IF
        if (
            len(instructions) > start
            and instructions[start]
            and not pipeline_state["IF"] != slug
        ):
            if stall_here():
                continue
            if delay_here():
                continue
            pipeline_state["IF"] = start
            start = start + 1

        # print(start)
        # print(len(instructions))
        # print(pipeline_state)

        filtered_state = {
            key: value for key, value in pipeline_state.items() if value != slug
        }
        if filtered_state:
            current_cycle = {
                "cycle": cycle,
                "state": filtered_state,
            }
            cycle_state.append(current_cycle)

        # end of instructions
        if len(instructions) < start:
            start = slug

        # end of instructions
        if start == slug:
            break

    return cycle_state
